import { Body, Param, Controller, Get, Post, Patch, Query } from '@nestjs/common';
import UserService from '@service/UserService';
import UserReq from '@model/req/UserReq';
import { ApiTags, ApiOperation, ApiParam, ApiQuery, ApiHeader } from '@nestjs/swagger';
import Page from '../model/Page';
import { query } from 'express';
@ApiTags('用户')
@Controller("user")
export default class UserController {
  constructor(private readonly userService: UserService) { }

  @ApiOperation({ summary: '登录', description: '登录' })
  @Post('Login')
  async userLogin(@Body() body: UserReq) {
    type User = {
      account: string,
      mail: string,
    }
    let user: User | null = await this.userService.getAccount(body.account);
    console.log(user);
    if (user !== null) {
      let { account, mail } = user;
      console.log(account, mail);
      let userList: User = { account, mail };
      let userData = new Page(userList, 200);
      return userData;
    }
  }


  @ApiOperation({ summary: '用户集', description: '用户集' })
  @Get("items")
  getItems(@Query() query: string) {
    return this.userService.get("1");
  }

  @ApiOperation({ summary: '添加', description: '添加' })
  @Post("add")
  add(@Body() user: UserReq): any {
    return null;

  }

  @ApiOperation({ summary: '修改', description: '修改' })
  @Patch(":id")
  update(@Param("id") id: string, @Body() user: UserReq): any {

    return null;
  }
}